import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hao/page/set/AboutPage.dart';
import 'package:hao/page/set/SetViewModel.dart';
import 'package:hao/page/user/LoginPage.dart';
import 'package:hao/utils/ImageUtil.dart';
import 'package:hao/utils/Utils.dart';

class SetPage extends StatefulWidget {
  const SetPage({Key? key}) : super(key: key);

  @override
  State<SetPage> createState() => _SetPageState();
}

class _SetPageState extends State<SetPage> with AutomaticKeepAliveClientMixin {
  final SetViewModel _viewModel = Get.put(SetViewModel());

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text("设置"),
      ),
      body: ListView(
        padding:const EdgeInsets.symmetric(horizontal: 15),
        children: [
          const SizedBox(
            height: 20,
          ),
          Center(
            child: Column(
              children: [loadAssetImage("icon", width: 100)],
            ),
          ),
          const SizedBox(
            height: 20,
          ),
          Obx(() => _itemWidget("版本号", _viewModel.version.value)),
          const SizedBox(
            height: 10,
          ),
          _itemWidget("关于APP", "", callback: () {
            Get.to(() => const AboutPage());
          }),
          const SizedBox(
            height: 10,
          ),
          _itemWidget("暗黑模式", _viewModel.model.value, callback: () {
            _viewModel.changeMode();
          }),
          const SizedBox(
            height: 30,
          ),
          // GestureDetector(
          //   child: LoginBgWidget("退出登录", () {
          //     _viewModel.logout();
          //   }),
          // )
        ],
      ),
    );
  }

  Widget _itemWidget(String title, String desc, {VoidCallback? callback}) {
    return GestureDetector(
      onTap: () {
        if (callback != null) {
          callback();
        }
      },
      child: Card(
        elevation: 3,
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(25)),
        ),
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 15),
          height: 50,
          child: Row(
            children: [
              Text(
                title,
                style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
              ),
              const Spacer(),
              Text(
                desc,
                style: const TextStyle(fontSize: 13),
              ),
              desc.isEmpty
                  ? const Icon(
                Icons.chevron_right,
              )
                  : const SizedBox()
            ],
          ),
        ),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
